import { Tooltip } from "ant-design-vue";
import dayjs from "dayjs";
import type { ActionProps, CommonSearchFile } from "~/types/enum";
import { $t } from "@/locales";

export enum LoginApi {
  GetList = "api/Log/GetListc",
  Export = "/api/Log/ExportDataa"
}
export class LoginAction {
  actionPros: ActionProps = {
    addCode: "",
    deleteCode: "",
    updateCode: "",
    queryCode: "LoginlogGetList",
    importCode: "",
    exportCode: "LoginlogExport",
    downImportCode: "",
    reductionCode: "",
    recyclebinCode: ""
  };
}
export interface LoginInfo {
  Id: string;
  uId: string;
  logincode: string;
  loginouttime: string;
  ipaddress?: string;
  ipv4address?: string;
  lmacaddress?: string;
  osystem?: string;
  osystemtype?: string;
  loginid?: string;
  onlinetime?: string;
  browser?: string;
  status?: string;
  Remark?: string;
  cTime?: Date;
  uTime?: Date;
}

export const displayColumns = (): any => {
  return [
    {
      key: "index",
      title: $t("common.index"),
      dataIndex: "index",
      align: "center",
      width: 64
    },
    {
      key: "logincode",
      dataIndex: "logincode",
      title: "登录账号",
      align: "center",
      width: 160
    },
    {
      key: "cTime",
      dataIndex: "cTime",
      title: "登录系统时间",
      align: "center",
      width: 140
    },
    {
      key: "ipaddress",
      dataIndex: "ipaddress",
      title: "IP地址",
      align: "center",
      width: 140
    },
    {
      key: "lmacaddress",
      dataIndex: "lmacaddress",
      title: "MAC地址",
      align: "center",
      width: 140,
      ellipsis: {
        showTitle: false
      },
      customRender(opt: any) {
        return (
          <Tooltip placement="topLeft" title={opt.text}>
            <span style="cursor: pointer;">{opt.text}</span>
          </Tooltip>
        );
      }
    },
    {
      key: "osystem",
      dataIndex: "osystem",
      title: "操作系统名称",
      align: "center",
      width: 140,
      ellipsis: {
        showTitle: false
      },
      customRender(opt: any) {
        return (
          <Tooltip placement="topLeft" title={opt.text}>
            <span style="cursor: pointer;">{opt.text}</span>
          </Tooltip>
        );
      }
    },
    {
      key: "osystemtype",
      dataIndex: "osystemtype",
      title: "操作系统类型",
      align: "center",
      width: 140,
      ellipsis: {
        showTitle: false
      },
      customRender(opt: any) {
        return (
          <Tooltip placement="topLeft" title={opt.text}>
            <span style="cursor: pointer;">{opt.text}</span>
          </Tooltip>
        );
      }
    },
    {
      key: "browser",
      dataIndex: "browser",
      align: "center",
      title: "浏览器",
      width: 260,
      ellipsis: {
        showTitle: false
      },
      customRender(opt: any) {
        return (
          <Tooltip placement="topLeft" title={opt.text}>
            <span style="cursor: pointer;">{opt.text}</span>
          </Tooltip>
        );
      }
    }
  ];
};

export const apiParams = (): any => {
  return {
    sortFile: "Id",
    sortType: "desc",
    files: "*",
    pageIndex: 1,
    pageSize: 20,
    logincode: "",
    ipaddress: "",
    status: "-1",
    stime: dayjs(dayjs(new Date()).format("YYYY-MM-DD 00:00:00")),
    etime: dayjs(dayjs(new Date()).format("YYYY-MM-DD 23:59:59")),
    sttime: dayjs(new Date()).format("YYYY-MM-DD 00:00:00"),
    ettime: dayjs(new Date()).format("YYYY-MM-DD 23:59:59")
  };
};

export const searchForm = (): CommonSearchFile[] => {
  return [
    {
      span: 24,
      md: 12,
      lg: 3,
      name: "logincode",
      placeholder: "登录账号",
      allowClear: false,
      type: "input"
    },
    {
      span: 24,
      md: 12,
      lg: 3,
      name: "ipaddress",
      placeholder: "IP地址",
      allowClear: false,
      type: "input"
    }
  ];
};
